/**
 *
 */
package Start;

import java.io.*;
import java.util.*;
import java.text.*;
import java.math.*;
import java.util.regex.*;
/**
 * @author Jake
 *
 */
public class Q3 {
 	static Stack<Integer> polish = new Stack<Integer>();
	
	
    public static void main(String[] args) {
     	String input = null;
     	int fail = 0;
    	Integer dec = 0;
    	Integer hex = 0;
    	String soln = null;
    	
    	
        /* Enter your code here. Read input from STDIN. Print output to STDOUT. Your class should be named Solution. */
    	/* One way to take in input?????*/
    	
    	Scanner in = new Scanner(System.in);
    	input = in.nextLine();
    	
    	
    
    	/* i think this is RIGHT !!!! refrence http://www.mkyong.com/java/how-to-get-the-standard-input-in-java/

   	 BufferedReader br = 
             new BufferedReader(new InputStreamReader(System.in));

   	 	try {
			input = br.readLine();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		*/     	
     	input = input.toUpperCase();
     	String delims = "[ ]+";
     	String[] tokens = input.split(delims);
     	
     	if(tokens.length < 21){
     		
       	for(int i = 0; i<tokens.length; i++ ){
     		fail = tokenEval(tokens[i]);
     		if(fail == -1){
     			break;
     		}
     	}
    if (fail == -1){
    	System.out.print("ERROR");
    }
    else{
    	dec = polish.pop();
    	hex = dec/4096;
    	if(hex == 15){
    		soln = "F";
    	}
    	else if(hex == 14){
    		soln = "E";
    	}
    	else if(hex == 13){
    		soln = "D";
    	}
    	else if(hex == 12){
    		soln = "C";
    	}
    	else if(hex == 11){
    		soln = "B";
    	}
    	else if(hex == 10){
    		soln = "A";
    	}
    	else{
    		soln = hex.toString();
    	}
    	dec -= hex*4096;
    	
    	hex = dec/256;
    	if(hex == 15){
    		soln = soln.concat("F");
    	}
    	else if(hex == 14){
    		soln = soln.concat("E");
    	}
    	else if(hex == 13){
    		soln = soln.concat("D");
    	}
    	else if(hex == 12){
    		soln = soln.concat("C");
    	}
    	else if(hex == 11){
    		soln = soln.concat("B");
    	}
    	else if(hex == 10){
    		soln = soln.concat("A");
    	}
    	else{
    		soln = soln.concat(hex.toString());
    	}
    	dec -= hex*256;
    	
    	hex = dec/16;
    	if(hex == 15){
    		soln = soln.concat("F");
    	}
    	else if(hex == 14){
    		soln = soln.concat("E");
    	}
    	else if(hex == 13){
    		soln = soln.concat("D");
    	}
    	else if(hex == 12){
    		soln = soln.concat("C");
    	}
    	else if(hex == 11){
    		soln = soln.concat("B");
    	}
    	else if(hex == 10){
    		soln = soln.concat("A");
    	}
    	else{
    		soln = soln.concat(hex.toString());
    	}
    	dec -= hex*16;
    	
    	hex = dec/1;
    	if(hex == 15){
    		soln = soln.concat("F");
    	}
    	else if(hex == 14){
    		soln = soln.concat("E");
    	}
    	else if(hex == 13){
    		soln = soln.concat("D");
    	}
    	else if(hex == 12){
    		soln = soln.concat("C");
    	}
    	else if(hex == 11){
    		soln = soln.concat("B");
    	}
    	else if(hex == 10){
    		soln = soln.concat("A");
    	}
    	else{
    		soln = soln.concat(hex.toString());
    	}
    	dec -= hex*1;
    	
    	
    	System.out.print(soln); 	
    	

    }
     	}
     	else{
     		System.out.print("ERROR");
     	}
    
    }
	
    
    public static int tokenEval(String token){
		int output;
		int hold = 0;
		int temp1 = 0;
		int temp2 = 0;
		
		if(token.equals("+")){
			if(polish.empty()){
				return -1;
			}
			temp1 = polish.pop();
			if(polish.empty()){
				return -1;
			}
			temp2 = polish.pop();
			hold = temp1 + temp2;
			if(hold > 65535)
				hold = 65535;
			polish.push(hold);
			
		}
		else if(token.equals("-")){
			if(polish.empty()){
				return -1;
			}
			temp1 = polish.pop();
			if(polish.empty()){
				return -1;
			}
			temp2 = polish.pop();
			hold = temp2 - temp1;
			if (hold < 0)
				hold = 0;
			polish.push(hold);
			
		}
		else if(token.equals("&")){
			if(polish.empty()){
				return -1;
			}
			temp1 = polish.pop();
			if(polish.empty()){
				return -1;
			}
			temp2 = polish.pop();
			hold = temp1 & temp2;
			polish.push(hold);
			
		}
		else if(token.equals("|")){
			if(polish.empty()){
				return -1;
			}
			temp1 = polish.pop();
			if(polish.empty()){
				return -1;
			}
			temp2 = polish.pop();
			hold = temp1 | temp2;
			polish.push(hold);
						
		}
		else if(token.equals("~")){
			if(polish.empty()){
				return -1;
			}
			temp1 = polish.pop();
			hold = ~temp2;
			polish.push(hold);
						
		}
		else if(token.equals("X")){
			if(polish.empty()){
				return -1;
			}
			temp1 = polish.pop();
			if(polish.empty()){
				return -1;
			}
			temp2 = polish.pop();
			hold = temp1^temp2;
			polish.push(hold);
						
		}
		else{
			char[] hex = token.toCharArray();
			if (hex.length > 4){
				return -1;
			}
			for(int i = 0; i < hex.length;i++){
				if(hex[i] == '0'){
					hold += 0*Math.pow(10,i);
				}
				else if(hex[i] == '1'){
					hold += 1*Math.pow(10,i);
				}
				else if(hex[i] == '2'){
					hold += 2*Math.pow(10,i);
				}
				else if(hex[i] == '3'){
					hold += 3*Math.pow(10,i);
				}
				else if(hex[i] == '4'){
					hold += 4*Math.pow(10,i);
				}
				else if(hex[i] == '5'){
					hold += 5*Math.pow(10,i);
				}
				else if(hex[i] == '6'){
					hold += 6*Math.pow(10,i);
				}
				else if(hex[i] == '7'){
					hold += 7*Math.pow(10,i);
				}
				else if(hex[i] == '8'){
					hold += 8*Math.pow(10,i);
				}
				else if(hex[i] == '9'){
					hold += 9*Math.pow(10,i);
				}
				else if(hex[i] == 'A'){
					hold += 10*Math.pow(10,i);
				}
				else if(hex[i] == 'B'){
					hold += 11*Math.pow(10,i);
				}
				else if(hex[i] == 'C'){
					hold += 12*Math.pow(10,i);
				}
				else if(hex[i] == 'D'){
					hold += 13*Math.pow(10,i);
				}
				else if(hex[i] == 'E'){
					hold += 14*Math.pow(10,i);
				}
				else if(hex[i] == 'F'){
					hold += 15*Math.pow(10,i);
				}
				else{
					return -1;
				}				
			}
			polish.push(hold);
		}
    	
    	return 0;
    }
       
}

